<template>
  <router-view></router-view>
</template>

<script>
import { useRouter } from "vue-router";
import { getLocalData } from "./util";
import config from "./config";

export default {
  setup() {
    const router = useRouter()
    // 全局前置守卫
    router.beforeEach((to, from, next) => {
      if (to.path === "/login") {
        next();
      } else {
        // 判断有没有登录
        if (!getLocalData(config.S_TOKEN)) {
          next({
            path: "/login",
          });
        } else {
          // 放行
          next();
        }
      }
    });
  },
};
</script>

<style lang="less">
@import 'assets/less/base.less';
@import 'assets/fonts/iconfont.css';
</style>
